﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TaxBiz.House;
using TaxEntity.House;
using BaseData.UI;
using TaxBiz.Tax;
using TaxEntity.Tax;

namespace Admin.AjaxPage
{
    public partial class HouseInfo : BaseCommon.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!HasPower())
            //{
            //    Jscript.AlertAndGoBack("您权限不足，不能操作");
            //    return;
            //}
            string retMessage = string.Empty;
            string action = PageContext.GetRequest("action");

            switch (action.ToLower())
            {
                case "gethouse":
                    string certificateID = PageContext.GetRequest("CertificateID");
                    HouseInfoEntity he = new HouseInfoBiz().GetEntityByCertificateID(certificateID);
                    if (he != null && (!isQueryDepartmentOnly || (isQueryDepartmentOnly && he.DepartmentID == UserLogin.DepartmentID)))
                    {
                        retMessage = "[{\"Name\":\"" + he.Name + "\""
                            + ",\"IDCardNum\":\"" + he.IDCardNum + "\""
                            + ",\"TudiArea\":\"" + he.TudiArea + "\""
                            + "}]";
                        //retMessage = he.Name;
                    }
                    else
                    {
                        retMessage = "[]";
                    }
                    break;
                case "gethousedetail":
                    certificateID = PageContext.GetRequest("CertificateID");
                    int? year = PageContext.GetRequestInt("year");
                    he = new HouseInfoBiz().GetEntityByCertificateID(certificateID);
                    if (he != null && (!isQueryDepartmentOnly || (isQueryDepartmentOnly && he.DepartmentID == UserLogin.DepartmentID)))
                    {
                        retMessage = "[{\"Name\":\"" + he.Name + "\""
                            + ",\"IDCardNum\":\"" + he.IDCardNum + "\""
                            + ",\"TudiArea\":\"" + he.TudiArea + "\""
                            + ",\"FangchanArea\":\"" + he.FangchanArea + "\""
                            + ",\"OriginalPrice\":\"" + he.OriginalPrice + "\""
                            + ",\"TudiArea\":\"" + he.TudiArea + "\""
                            + ",\"RemainPrice\":\"" + he.RemainPrice + "\""
                            + ",\"DiduanID\":\"" + he.DiduanID + "\""
                            //+ ",\"HouseType\":\"" + he.HouseType + "\"";
                            + ",\"HouseType\":\"{HouseType}\"";
                        //出租屋信息
                        long rentID = 0;
                        decimal rentPrice = 0M;
                        //if (he.HouseType == "出租")
                        //{
                        RentInfoEntity rie = new RentInfoBiz().GetEntityById(certificateID, year.HasValue ? year.Value : DateTime.Now.Year);
                        if (rie != null)
                        {
                            retMessage = retMessage.Replace("{HouseType}", rie.HouseType2);
                            rentID = rie.Id;
                            rentPrice = rie.RentPrice.HasValue ? rie.RentPrice.Value : 0;
                        }
                        //}
                        //应税信息
                        TaxRequireEntity tre = new TaxRequireBiz().GetEntityById(certificateID, year.HasValue ? year.Value : DateTime.Now.Year, rentID);
                        if (tre != null)
                        {
                            retMessage += ",\"RequireTax\":{";
                            retMessage += "\"TotalTax\":" + BaseData.Common.Kernel.GetDecimalFromObject(tre.TotalTax);
                            retMessage += ",\"YingyeTax\":" + BaseData.Common.Kernel.GetDecimalFromObject(tre.YingyeTax);
                            retMessage += ",\"PersonalTax\":" + BaseData.Common.Kernel.GetDecimalFromObject(tre.PersonalTax);
                            retMessage += ",\"CityTax\":" + BaseData.Common.Kernel.GetDecimalFromObject(tre.CityTax);
                            retMessage += ",\"JiaoyuTax\":" + BaseData.Common.Kernel.GetDecimalFromObject(tre.JiaoyuTax);
                            retMessage += ",\"DifangJiaoyuTax\":" + BaseData.Common.Kernel.GetDecimalFromObject(tre.DifangJiaoyuTax);
                            retMessage += ",\"YinhuaTax\":" + BaseData.Common.Kernel.GetDecimalFromObject(tre.YinhuaTax);
                            retMessage += ",\"FangchanTax\":" + BaseData.Common.Kernel.GetDecimalFromObject(tre.TudiTax);
                            retMessage += ",\"TudiTax\":" + BaseData.Common.Kernel.GetDecimalFromObject(tre.FangchanTax);
                            retMessage += "}";
                        }
                        retMessage += ",\"RentID\":\"" + rentID + "\"";
                        retMessage += ",\"RentPrice\":\"" + rentPrice + "\"";
                        retMessage += "}]";
                    }
                    else
                    {
                        retMessage = "[]";
                    }
                    break;
            }
            Response.ContentType = "text/plain";
            Response.Write(retMessage);
        }
    }
}